package fanxin;

import org.omg.CORBA.PUBLIC_MEMBER;

public class JiHe<T> {
    private T[] arr;
    private int size;

    public JiHe(int size) {
        this.size = size;
        arr=(T[]) new Object[size];
    }
    public void set(int index,T val){
        arr[index]=val;

    }
    public T get(int index){
        return arr[index];
    }
    public void show(){
        for (T e:arr){
            System.out.println(e);
        }
        System.out.println();
    }
    public int length(){//取长度
        return size;
    }
    public static void main(String[] args){
        JiHe<Integer> jh=new JiHe<>(5);
        jh.set(2,35);
        jh.set(0,46);
        jh.show();
        out(jh);
        System.out.println(jh.get(2));
        JiHe<Student> jh2=new JiHe<>(5);
        Student s1=new Student("孙悟空",500);
        Student s2=new Student("孙悟空",500);
        Student s3=new Student("孙悟空",500);
        jh2.set(0,s1);
        jh2.set(1,s2);
        jh2.set(2,s3);
        jh2.show();
        //out(jh2);错误，因为Student不是Number的子类
    }
    public static void out(JiHe<? extends Number>jh){
        for (int i=0;i<jh.length();i++){
            System.out.println(jh.get(i));
        }
        System.out.println();
    }
}
